package com.yint.tree;

/**
 * 装饰节点
 * <p>
 * Created by 殷田 on 2018/5/3.
 */
public abstract class Decorator extends Leaf {

    private Leaf sub;

    public final void setSub(Leaf sub) {
        this.sub = sub;
    }

    protected final Leaf getSub() {
        return sub;
    }

    @Override
    protected boolean onEntry(Tree tree) {
        return getSub() != null;
    }

    @Override
    protected void onLeave(Tree tree, STATUS state) {
        getSub().leave(tree);
    }
}
